/**
 * Created by jack on 2017/12/14.
 */

'use strict';

goog.provide('Blockly.JavaScript.Data');

goog.require('Blockly.JavaScript');


Blockly.JavaScript.data_variable = function() {
  // Variable getter.
  var pin=this.getFieldValue('VARIABLE');

  var varName = Blockly.JavaScript.variableDB_.getName(pin,
      Blockly.VARIABLE_CATEGORY_NAME);
  // Blockly.JavaScript.setups_['setup_var' + varName] = varName + ' = ' + 0 + ';\n';
  var code=varName;
  return [code, Blockly.JavaScript.ORDER_ATOMIC];
};


Blockly.JavaScript.data_setvariableto = function() {
  // Variable setter.
  var argument0 = Blockly.JavaScript.valueToCode(this, 'VALUE',
      Blockly.JavaScript.ORDER_ASSIGNMENT) || '0';
  var varName = Blockly.JavaScript.variableDB_.getName(this.getFieldValue('VARIABLE'),
      Blockly.VARIABLE_CATEGORY_NAME);
  return  varName + ' = ' + argument0 + ';\n';
};


Blockly.JavaScript.data_changevariableby = function() {
  // Variable setter.
  var argument0 = Blockly.JavaScript.valueToCode(this, 'VALUE',
      Blockly.JavaScript.ORDER_ASSIGNMENT) || '0';
  var varName = Blockly.JavaScript.variableDB_.getName(this.getFieldValue('VARIABLE'),
      Blockly.VARIABLE_CATEGORY_NAME);
  var new_arg=parseInt(argument0.replace('"',''));
  return varName + ' = ' + new_arg + ';\n';
};